import java.util.Arrays;
import java.util.function.IntToDoubleFunction;

public class ArraysTest {
    /*
    掌握Arrays类的常用方法
     */
    public static void main(String[] args) {
        int[] arr =  {10, 20, 30, 40, 50, 60};
        System.out.println(Arrays.toString(arr));  // 返回数组内容

        int[] arr2 = Arrays.copyOfRange(arr, 1, 4);
        System.out.println(Arrays.toString(arr2));  // 拷贝数组  包前不包后

        int[] arr3 = Arrays.copyOf(arr, 10);  // 拷贝数组 可以指定新数组的长度
        int[] arr4 = Arrays.copyOf(arr, 1);
        System.out.println(Arrays.toString(arr3));
        System.out.println(Arrays.toString(arr4));

        // 把数组中的原数据改为新数据又存进去
        double[] prices = {80, 90, 100};
        Arrays.setAll(prices, new IntToDoubleFunction() {
            @Override
            public double applyAsDouble(int value) {
                // value = 0 1 2
                return prices[value] * 0.8;
            }
        });

        System.out.println(Arrays.toString(prices));

        // 排序(默认升序)
        int[] arr5 = {10, 20, 2, 40, 14, 60};
        Arrays.sort(arr5);
        System.out.println(Arrays.toString(arr5));

    }
}
